package com.edu.security.controller;

import com.edu.security.entity.User;
import com.edu.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<User> getUserList() {
        return userService.list();
    }

    @PostMapping("/add")
    public void addUser(@RequestBody User user) {
        userService.saveUserDetails(user);
    }

    @GetMapping("/test")
    @PreAuthorize("hasAuthority('USER_LIST')")
    public String test(){
        return "Hello";
    }
}
